// JjcapData.h: interface for the CJjcapData class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_JJCAPDATA_H__3FABFA69_4506_4FE1_99D3_E19A6C2FCA5F__INCLUDED_)
#define AFX_JJCAPDATA_H__3FABFA69_4506_4FE1_99D3_E19A6C2FCA5F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#undef _LIST_
#include <list>

#include "packdef.h"

using namespace std;

struct cap_data
{
	int index;
	pcap_pkthdr hdr;
	LPBYTE buf;
	cap_data()
	{
		memset(this, 0, sizeof(*this));
	}
};

typedef struct PacketStatistic
{
	int last_packs;
	int total;
	int ip;
	int udp;
	int tcp;
	int icmp;
	int igmp;
	int dns;
	int arp;
	int http;
	int oicq;
	int others;
	int last_bytes;
	int total_bytes;
	int ip_bytes;
	int udp_bytes;
	int tcp_bytes;
	int icmp_bytes;
	int igmp_bytes;
	int dns_bytes;
	int arp_bytes;
	int http_bytes;
	int oicq_bytes;
	int others_bytes;
	volatile bool update_speed;

	void Clear()
	{
		memset(this, 0, sizeof(*this));
	}
	PacketStatistic()
	{
		Clear();
	}
}PacketStatistic;

class CJjcapData
{
public:
	CJjcapData();
	virtual ~CJjcapData();

public:
	static void GetOICQCmdName(u_short cmd, CString& name);
	static int GetDNSRequestDomain(int begin, pack_hdr& h, CString& name);
	static int GetDNSRequestDomainByLength(int begin, pack_hdr& h, CString& name, int len);
	static int GetDNSRequestDomainClass(int begin, pack_hdr& h, CString& type, CString& clas);
	static void InterpretHeader(const pcap_pkthdr* caphdr, pack_hdr* phdr, const u_char* content);
	const cap_data* FindData(int index);
	const cap_data* AppendData(int index, const pcap_pkthdr* hdr, const u_char* data);
	void DeleteAllData();
	void Unload();
	void Load();
	HANDLE hthread;
	timeval start_time;
	timeval end_time;
	bool use_promisc;
	list<cap_data> cap_list;
	pcap_if_t* adapter_list;
	pcap_if_t* adapter_info;
	pcap_t* adapter;
	int max_pack_cap;
	CString filter_exp;
	volatile int cap_cnt;
	volatile int break_loop;
	PacketStatistic pack_stat;
};

#endif // !defined(AFX_JJCAPDATA_H__3FABFA69_4506_4FE1_99D3_E19A6C2FCA5F__INCLUDED_)
